<?php

include dirname(dirname(dirname(__FILE__))) . '/include/common.php';

class webServiceCheckToDoComplete extends core {

    public function process() {
        $todo_id = intval($_POST['todo_id']);
        $user_id = intval($_POST['user_id']);
        $complete = intval($_POST['complete']);
        if($complete !=0 && $complete !=1){
            $complete=0;
        }
        $data = $this->db->get_row("SELECT * FROM todo_lists WHERE `todo_id`='$todo_id' AND `user_id`='$user_id'");
        if ($data) {         
            $query = "UPDATE todo_lists SET `is_done`='$complete' WHERE `todo_id`= '$todo_id' AND `user_id`='$user_id'";

            if ($this->db->query($query)===false) {

                $this->_JSONResponse(array('error' => 1, 'msg' => 'Oops, something went wrong. Please try again'));
            } else { 
                if($complete==1){
                    $this->_JSONResponse(array('error' => 0, 'msg' => 'Task has been completed.'));
                }else{
                    $this->_JSONResponse(array('error' => 0, 'msg' => 'Task is in progress.'));
                }
            }
        } else {
            $this->_JSONResponse(array('error' => 1, 'msg' => 'Task does not exist'));
        }
    }

}

$processor = new webServiceCheckToDoComplete();
$processor->process();
?>